<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Listening to Events</title>
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }

      #floating-panel {
        position: absolute;
        top: 10px;
        left: 25%;
        z-index: 5;
        background-color: #fff;
        padding: 5px;
        border: 1px solid #999;
        text-align: center;
        font-family: 'Roboto','sans-serif';
        line-height: 30px;
        padding-left: 10px;
      }
    </style>
</head>
<body>
<div id="floating-panel">
    <input type="button" value="锁定范围" onclick="lock();"></input>
    <input type="button" value="编辑范围" onclick="unlock();"></input>
</div>
<div id="map"></div>
<script>

      var map;

      var infoWindow;

      var cityCircle;

      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: 39.669, lng: 116.016},
          zoom: 9
        });

        var bounds = {
          north: 40.212,
          south: 39.631,
          east: 116.765,
          west: 116.0160
        };

        cityCircle = new google.maps.Circle({
            strokeColor: '#FF0000',
            strokeOpacity: 0.8,
            strokeWeight: 2,
            fillColor: '#FF0000',
            fillOpacity: 0.35,
            map: map,
            editable: false,
            draggable: false,
            center: {lat: 39.669, lng: 116.016},
            bounds: bounds,
            radius: Math.sqrt(100000) * 100
        });

        cityCircle.addListener('bounds_changed', showNewRect);

        infoWindow = new google.maps.InfoWindow();
      }

      function showNewRect(event) {
        var ne = cityCircle.getBounds().getNorthEast();
        var sw = cityCircle.getBounds().getSouthWest();
        console.log(cityCircle.getBounds())
        var contentString = '<b>Rectangle moved.</b><br>' +
            'New north-east corner: ' + ne.lat() + ', ' + ne.lng() + '<br>' +
            'New south-west corner: ' + sw.lat() + ', ' + sw.lng();

        // Set the info window's content and position.
        infoWindow.setContent(contentString);
        infoWindow.setPosition(ne);

        infoWindow.open(map);
      }
      function lock(){
        console.log(cityCircle)
        cityCircle.setEditable(false)
        cityCircle.setDraggable(false)
        console.log(cityCircle)
        cityCircle.setMap(map);
      }

      function unlock(){
        console.log(cityCircle)
        cityCircle.editable = true
        cityCircle.draggable = true
        console.log(cityCircle)

      }
    </script>
<script async defer
        src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCta9vOm1x7q3UqBeb3dWvqUOhpZTQBcR4&callback=initMap">
</script>
</body>
</html>